
/**
 * 根据name获取url的参数值
 * @param name
 * @returns {string|null}
 */
export const getQueryString = name => {
  let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  let r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return unescape(r[2]);
  }
  return null;
}
/**
 * 去掉url？后面的参数
 * @param url
 * @returns {*|string}
 */
export const getUrl = url => {
  let res = url;
  if(url.indexOf("?") > -1){
    let index = url.indexOf("?");
    res = res.substr(0,index);

  }
  return res;
}

export const getUrlParmas = name => {
  let url = window.location.href;
  console.log(url)
  if(url.indexOf("?") > -1){
    url = url.replace("?","&");
  }
  let vars = url.split("&");
  console.log(vars)
  for (let i=0;i<vars.length;i++) {
    let pair = vars[i].split("=");
    if(pair[0] == name){
      return pair[1];
    }
  }
  return(false);
}


